#include <iostream>
/*
 * @Author: 缄默
 * @Date: 2021-09-16 23:24:50
 * @LastEditors: 缄默
 * @LastEditTime: 2021-12-14 11:18:32
 */

using namespace std;

class Target {
public:
    virtual void request() = 0;
    virtual ~Target() {}
};

class Adaptee {
public:
    void specificRequest() {
        cout << "adaptee::specificRequest.." << endl;
    }
};


//类适配器，通过双重继承实现
class ClassAdapter : public Target, private Adaptee {
public:
    ClassAdapter() {
    }
    void request() {
        cout << "ClassAdapter..." << endl;
        specificRequest();
    }
};

//对象适配器
class ObjectAdapter : public Target {
private:
    Adaptee *_ade;
public:
    ObjectAdapter(Adaptee *ade) {
        _ade = ade;
    }
    void request() {
        cout << "ObjectAdapter..." << endl;
        _ade->specificRequest();
    }
};


int main() {
    //类适配器用法
    Target *classAdapter = new ClassAdapter();
    classAdapter->request();

    delete classAdapter;

    //对象适配器用法
    Adaptee *adaptee = new Adaptee();
    Target *objectAdapter = new ObjectAdapter(adaptee);
    objectAdapter->request();

    delete adaptee;
    delete objectAdapter;
    return 0;
}